package com.hdu.controller.contentManagement;


import com.hdu.dto.CollectCourseDTO;
import com.hdu.exception.ValidationGroups;
import com.hdu.pojo.PageBean;
import com.hdu.pojo.Result;
import com.hdu.service.ICollectCourseService;
import com.hdu.util.UserUtils;
import com.hdu.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/collect")
@Api(value = "课程收藏编辑接口", tags = "课程收藏编辑接口")
public class CollectCourseController {
    @Resource
    ICollectCourseService collectCourseService;

    @ApiOperation("课程查询接口")
    @PostMapping("/list")
    public Result<PageBean<CollectCourseDTO>> list(@RequestBody BaseParamVo baseParamVo) {
        int userInfoId = UserUtils.getLoginUser().getUserInfoId();
        return Result.success(collectCourseService.queryCollectCourseList(userInfoId, baseParamVo));
    }

    @ApiOperation("新增课程收藏接口")
    @PostMapping
    public Result<?> insert(@RequestBody @Validated(ValidationGroups.Insert.class) AddCollectVo addCollectVo) {
        addCollectVo.setUserId(UserUtils.getLoginUser().getUserInfoId());
        return Result.success(collectCourseService.createCollectCourse(addCollectVo));
    }

    @ApiOperation("删除课程")
    @DeleteMapping("/{courseId}")
    public Result<?> delete(@PathVariable Long courseId) {
        int userInfoId = UserUtils.getLoginUser().getUserInfoId();
        collectCourseService.removeCollectCourse(userInfoId, courseId);
        return Result.success();
    }
}
